<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:n="http://java.sun.com/jstl/core">
<ui:composition template="/Templates/Template.xhtml">

	<ui:define name="contenu">


		<c:choose>
			<c:when test="#{loginBean.exist()}">

				<!-- Data table -->

				<h:form id="a">
					<p:growl id="growl" showDetail="true" sticky="true" life="4000" />
					<p:dataTable var="patient" value="#{patientBean.patients}"
						id="AjoutTab" widgetVar="patientTable" paginatorPosition="bottom"
						emptyMessage="patient non trouvé" paginator="true" rows="10"
						paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
						rowsPerPageTemplate="5,10,15" sortMode="multiple"
						style="width:950px;font-size:14px;font-weight:400;"
						filteredValue="#{patientTableBean.filtredpatients}">

						<f:facet name="header">
							<p:outputPanel>
								<h:outputText value="Recherche:" />
								<p:inputText id="globalFilter" onkeyup="patientTable.filter()"
									style="width:80px;" />
								<c:if test="#{loginBean.e.libelle!='Administrateur'}">
									<p:commandButton value="&nbsp;Ajouter une patient"
										style="float:right;height:30px" image="ui-icon-circule-plus"
										actionListener="#{patientBean.ajoutEvent()}"
										update=":edit:editP" oncomplete="patientAjout.show()" />
								</c:if>
							</p:outputPanel>
						</f:facet>

						<p:column id="patientId" headerText="ID">

							<h:outputText value="#{patient.id}" />


						</p:column>
						<p:column headerText="Nom" id="patientNom"
							filterBy="#{patient.nom}" filterMatchMode="contains">

							<h:outputText value="#{patient.nom}" />

						</p:column>
						<p:column headerText="Prenom" id="patientPrenom"
							filterBy="#{patient.prenom}" filterMatchMode="contains">
							<h:outputText value="#{patient.prenom}" />
						</p:column>
						<p:column headerText="Etat Civil" id="patientetat">
							<h:outputText value="#{patient.etatcivil}" />
						</p:column>
						<p:column headerText="tel" id="patienttel">
							<h:outputText value="#{patient.tel}" />
						</p:column>
						<p:column headerText="profession" id="patientprofession">
							<h:outputText value="#{patient.profession}" />
						</p:column>
						<p:column headerText="CIN" id="patientCIN"
							filterBy="#{patient.cin}" filterMatchMode="exact">
							<h:outputText value="#{patient.cin}" />
						</p:column>
						<c:choose>
							<c:when test="#{loginBean.e.libelle=='Administrateur'}">
								<p:column style="width:4%">
									<p:commandButton id="Editer" update=":Actualise:displaye"
										icon="ui-icon-pencil" oncomplete="patientEdit.show();"
										title="Editer"
										actionListener="#{patientBean.editEvent(patient.id)}" />

								</p:column>

								<p:column style="width:4%">
									<p:commandButton id="Supprimer" icon="ui-icon-trash"
										update=":supp:confirmDialog" oncomplete="confirmation.show()"
										title="Supprime">
										<f:setPropertyActionListener value="#{patient}"
											target="#{patientBean.patient}" />
									</p:commandButton>
								</p:column>
							</c:when>
							<c:otherwise>
								<p:column style="width:4%">
									<p:commandButton id="Rdv" icon="ui-icon-note"
										title="Rendez Vous" oncomplete="eventDialog.show()"
										update=":RDV:details">
										<f:setPropertyActionListener value="#{patient.id}"
											target="#{rendezVousBean.patientid}" />
									</p:commandButton>
								</p:column>
								<p:column style="width:4%">
									<p:commandButton id="Visite" icon="ui-icon-note" title="Visite"
										oncomplete="visiteDialog.show()"
										update=":visite:visiteDetails">
										<f:setPropertyActionListener value="#{patient.id}"
											target="#{visiteBean.patientid}" />
										<f:setPropertyActionListener value="#{loginBean.e.id}"
											target="#{visiteBean.medecinid}" />
									</p:commandButton>
								</p:column>
								<c:if test="#{loginBean.e.libelle=='Medecin'}">
									<p:column style="width:4%">
										<p:commandButton id="mes" icon="ui-icon-note" title="Mesure"
											update=":consult:mesureDetails"
											onclick="consultDialog.show()">
											<c:if test="#{loginBean.e.libelle=='Medecin'}">
												<f:setPropertyActionListener value="#{loginBean.e.id}"
													target="#{mesureBean.medecinid}" />
											</c:if>
											<f:setPropertyActionListener value="#{patient.id}"
												target="#{mesureBean.patientid}" />

										</p:commandButton>
									</p:column>
								</c:if>
							</c:otherwise>
						</c:choose>
					</p:dataTable>

					<p:blockUI block="AjoutTab" trigger="AjoutTab">  
        LOADING<br />
						<p:graphicImage value="../resources/images/ajax-loader.gif" />
					</p:blockUI>
				</h:form>



				<!-- Ajout d un patient -->

				<h:form id="edit">

					<p:dialog header="Ajout de patient" widgetVar="patientAjout"
						showEffect="fade" hideEffect="explode" resizable="false"
						id="editP">

						<p:growl id="growledit" showDetail="true" sticky="true" />
						<h:panelGrid id="display" columns="2" cellpadding="4"
							style="margin:0 auto;">


							<h:outputLabel for="nom" value="" />
							<h:inputHidden value="#{patientBean.patient.id}" id="id"
								required="true" />

							<h:outputLabel for="nom" value="Nom:"
								style="color: black;font-weight: bold" />
							<h:inputText value="#{patientBean.patient.nom}" id="nom"
								required="true" requiredMessage="Nom" />
							<h:outputLabel for="prenom" value="Prenom:"
								style="color: black;font-weight: bold" />
							<h:inputText value="#{patientBean.patient.prenom}" id="prenom"
								required="true" requiredMessage="Prenom" />
							<h:outputLabel for="Etat" value="Etat Civil :"
								style="color: black;font-weight: bold" />
							<h:outputLabel for="tel" value="Telehpone :"
								style="color: black;font-weight: bold" />
							<p:selectOneListbox id="Etat"
								value="#{patientBean.patient.etatcivil}"
								requiredMessage="Etat Civil" required="true">
								<f:selectItem itemLabel="Marié(e)" itemValue="Marie" />
								<f:selectItem itemLabel="Celibataire" itemValue="Celibataire" />

							</p:selectOneListbox>
							<h:inputText value="#{patientBean.patient.tel}" id="tel" />
							<h:outputLabel for="profession" value="Profession :"
								style="color: black;font-weight: bold" />
							<h:outputLabel for="assurance" value="Assurance :"
								style="color: black;font-weight: bold" />
							<h:inputText value="#{patientBean.patient.profession}"
								id="profession" />
							<h:inputText value="#{patientBean.patient.assurance}"
								id="assurance" />


							<h:outputLabel for="Cin" value="CIN :"
								style="color: black;font-weight: bold" />
							<h:outputLabel for="Adresse" value="Adresse :"
								style="color: black;font-weight: bold" />
							<h:inputText value="#{patientBean.patient.cin}" id="Cin"
								required="true" requiredMessage="Cin" />
							<h:inputText value="#{patientBean.patient.adresse}" id="Adresse" />

						</h:panelGrid>
						<p:separator />
						<p:commandButton value="Enregistrer"
							update=":a:AjoutTab, :a:growl"
							actionListener="#{patientBean.ajoutp() }"
							oncomplete="patientAjout.hide()">
							<p:ajax listener="#{patientTableBean.filtredpatients}"></p:ajax>
						</p:commandButton>
					</p:dialog>

				</h:form>
				<!-- Modifier un Patient -->
				<h:form id="Actualise">

					<p:dialog header="Modification" widgetVar="patientEdit"
						resizable="false" id="editPer">

						<p:growl id="growledit" showDetail="true" sticky="true" />
						<h:panelGrid id="displaye" columns="2" cellpadding="4"
							style="margin:0 auto;">


							<h:outputLabel for="id" value="" />
							<h:inputHidden value="#{patientBean.patient.id}" id="id"
								required="true" />

							<h:outputLabel for="nom" value="Nom:"
								style="color: black;font-weight: bold" />
							<h:inputText value="#{patientBean.patient.nom}" id="nom"
								required="true" requiredMessage="Nom" />
							<h:outputLabel for="prenom" value="Prenom:"
								style="color: black;font-weight: bold" />
							<h:inputText value="#{patientBean.patient.prenom}" id="prenom"
								required="true" requiredMessage="Prenom" />
							<h:outputLabel for="Etat" value="Etat Civil :"
								style="color: black;font-weight: bold" />
							<h:outputLabel for="tel" value="Telehpone :"
								style="color: black;font-weight: bold" />
							<p:selectOneListbox id="Etat"
								value="#{patientBean.patient.etatcivil}"
								requiredMessage="Etat Civil" required="true">
								<f:selectItem itemLabel="Marié(e)" itemValue="Marie" />
								<f:selectItem itemLabel="Celibataire" itemValue="Celibataire" />

							</p:selectOneListbox>
							<h:inputText value="#{patientBean.patient.tel}" id="tel" />
							<h:outputLabel for="profession" value="Profession :"
								style="color: black;font-weight: bold" />
							<h:outputLabel for="assurance" value="Assurance :"
								style="color: black;font-weight: bold" />
							<h:inputText value="#{patientBean.patient.profession}"
								id="profession" />
							<h:inputText value="#{patientBean.patient.assurance}"
								id="assurance" />


							<h:outputLabel for="Cin" value="CIN :"
								style="color: black;font-weight: bold" />
							<h:outputLabel for="Adresse" value="Adresse :"
								style="color: black;font-weight: bold" />
							<h:inputText value="#{patientBean.patient.cin}" id="Cin"
								required="true" requiredMessage="Cin" />
							<h:inputText value="#{patientBean.patient.adresse}" id="Adresse" />

						</h:panelGrid>
						<p:separator />
						<p:commandButton value="Enregistrer"
							update=":a:AjoutTab, :a:growl"
							actionListener="#{patientBean.edition()}"
							oncomplete="patientEdit.hide()" />
					</p:dialog>

				</h:form>

				<!--  Suppression d un Patient -->
				<h:form id="supp">

					<p:dialog id="confirmDialog" showEffect="fade"
						header="Suppression d'un Patient" severity="alert"
						widgetVar="confirmation">
						<p:growl id="messages" showDetail="true" sticky="true" life="4000" />
						<h:inputHidden value="#{patientBean.patient.id}" id="supp"
							required="true" />
						<p:outputLabel
							value="Etes vous sûr de vouloir supprimer ce Patient ?" />
						<p:commandButton id="confirm" value="Yes Sure"
							update="messages,:a:AjoutTab" oncomplete="confirmation.hide()"
							actionListener="#{patientBean.delet()}" />
						<p:commandButton id="decline" value="Not Yet"
							onclick="confirmation.hide()" type="button" />

					</p:dialog>
				</h:form>
				<!-- Gestion de Rendez Vous -->

				<h:form id="RDV">
					<p:dialog widgetVar="eventDialog" header="Event Details"
						showEffect="clip" hideEffect="clip" id="details">
						<p:growl id="mess" showDetail="true" sticky="true" life="4000" />
						<h:panelGrid id="eventDetails" columns="2">

							<h:outputLabel for="rddv" value="" />
							<h:inputHidden value="#{rendezVousBean.patientid}" id="rddv"
								required="true" />


							<h:outputLabel for="to" value="Date :" />
							<p:calendar id="to" value="#{rendezVousBean.date}"
								pattern="yyyy/MM/dd" required="true"
								mindate="#{rendezVousBean.d()}"
								requiredMessage="Selectionner une Date">

								<p:ajax event="dateSelect" listener="#{rendezVousBean.test()}"
									update="test" />
							</p:calendar>
							<h:outputLabel for="Medecin" value="Medecin :" />
							<p:selectOneMenu id="Medecin" value="#{rendezVousBean.medecinid}"
								effect="drop" required="true"
								requiredMessage="Selectionner un Medecin">
								<f:selectItem itemLabel="Select One" itemValue="" />
								<f:selectItems value="#{rendezVousBean.medecins}" var="medd"
									itemLabel="#{medd.nom} #{medd.prenom}" itemValue="#{medd.id}" />
								<p:ajax listener="#{rendezVousBean.test()}" update="test" />
							</p:selectOneMenu>

							<h:outputText value="Heure RDV: " />

							<p:selectOneMenu value="#{rendezVousBean.h}" required="true"
								id="test" requiredMessage="Selectionner une Heure">
								<f:selectItem itemLabel="Select One" itemValue="" />
								<f:selectItems value="#{rendezVousBean.test()}" var="h"
									itemLabel="#{h.toString()}" itemValue="#{h.intValue()}" />

							</p:selectOneMenu>


							<h:outputLabel for="desc" value="Description :" />
							<p:inputTextarea id="desc" value="#{rendezVousBean.desc}" />





							<p:commandButton actionListener="#{rendezVousBean.ajoutRdv()}"
								update=":RDV:mess" value="Save" oncomplete="eventDialog.hide()">
								<p:ajax listener="#{rendezVousSchedule.remplir()}" />
							</p:commandButton>

						</h:panelGrid>
					</p:dialog>
				</h:form>
				<h:form id="visite">
					<p:dialog widgetVar="visiteDialog" header="Visite Details"
						showEffect="clip" hideEffect="clip" id="Visites">
						<p:growl id="mess" showDetail="true" sticky="true" life="4000" />
						<h:panelGrid id="visiteDetails" columns="3">

							<h:outputLabel for="patientid" value="" />
							<h:inputHidden value="#{visiteBean.patientid}" id="patientid" />
							<h:outputLabel value="" />
							<c:choose>
								<c:when test="#{loginBean.e.libelle=='Infermiere'}">
									<h:outputLabel for="Medecin" value="Medecin :" />
									<p:selectOneMenu id="Medecin" value="#{visiteBean.medecinid}"
										effect="drop" required="true"
										requiredMessage="Selectionner un Medecin">
										<f:selectItem itemLabel="Select One" itemValue="" />
										<f:selectItems value="#{visiteBean.medecins}" var="medd"
											itemLabel="#{medd.nom} #{medd.prenom}" itemValue="#{medd.id}" />

									</p:selectOneMenu>
									<h:outputLabel value="" />
								</c:when>
								<c:otherwise>
									<h:outputLabel for="medecin" value="" />
									<h:inputHidden value="#{visiteBean.medecinid}" id="medecin" />
									<h:outputLabel value="" />
								</c:otherwise>
							</c:choose>
							<p:outputLabel value="Description :" />
							<p:inputTextarea value="#{visiteBean.description}"
								maxlength="150" />
							<h:outputLabel value="" />

							<h:outputLabel value="Temperature :" />
							<p:inputText value="#{visiteBean.mesure.temperature}" />
							<h:outputLabel value="C°" />

							<h:outputLabel value="Pression :" />
							<p:inputText value="#{visiteBean.mesure.pression}" />
							<h:outputLabel value="" />

							<h:outputLabel value="Poids :" />
							<p:inputText value="#{visiteBean.mesure.poids}" />
							<h:outputLabel value="Kg" />

							<h:outputLabel value="Taille :" />
							<p:inputText value="#{visiteBean.mesure.taille}" />
							<h:outputLabel value="cm" />

							<p:commandButton update=":RDV:mess" value="Save"
								actionListener="#{visiteBean.add()}"
								oncomplete="visiteDialog.hide()" />

						</h:panelGrid>
					</p:dialog>
				</h:form>
				<h:form id="consult">
					<p:dialog widgetVar="consultDialog" header="Mesure Details"
						showEffect="clip" hideEffect="clip" id="mesures" resizable="false"
						closable="true" closeOnEscape="true">

						<h:panelGrid id="mesureDetails" columns="3">

							<h:outputLabel for="patientid" value="" />
							<p:inputText style="visibility:hidden;"
								value="#{mesureBean.patientid}" id="patientid" rendered="true">


							</p:inputText>
							<h:outputLabel value="" />
							<c:if test="#{loginBean.e.libelle=='Medecin'}">
								<h:outputLabel for="medid" value="" />
								<p:inputText style="visibility:hidden;"
									value="#{mesureBean.medecinid}" id="medid" rendered="true">
								</p:inputText>

								<h:outputLabel value="" />
							</c:if>


							<h:outputLabel for="Mesure" value="Mesure :" />
							<p:selectOneMenu id="Mesure" value="#{mesureAffBean.visiteid}"
								effect="drop" rendered="true">
								<f:selectItem itemLabel="Select One" itemValue="0" />
								<f:selectItems value="#{mesureBean.listevisite}" var="mesure"
									itemLabel="#{mesure.datedebv}" itemValue="#{mesure.idvisite}" />
								<p:ajax update="Detailsmes" listener="#{mesureAffBean.desc()}" />

							</p:selectOneMenu>
							<h:outputLabel value="" />
						</h:panelGrid>
						<h:panelGrid id="Detailsmes" columns="3">
							<h:outputLabel for="Descr" value="Desciption :" />
							<p:inputTextarea id="Descr" value="#{mesureAffBean.description}"
								rendered="true" />
							<p:outputLabel value="" />

							<h:outputLabel value="Temperature :" />
							<p:inputText value="#{mesureAffBean.mesure.temperature}"
								id="Temperature" disabled="true" rendered="true" />
							<h:outputLabel value="C°" />

							<h:outputLabel value="Pression :" />
							<p:inputText value="#{mesureAffBean.mesure.pression}"
								id="Pression" disabled="true" rendered="true" />
							<h:outputLabel value="" />

							<h:outputLabel value="Poids :" />
							<p:inputText value="#{mesureAffBean.mesure.poids}" id="Poids"
								disabled="true" rendered="true" />
							<h:outputLabel value="Kg" />

							<h:outputLabel value="Taille :" />
							<p:inputText value="#{mesureAffBean.mesure.taille}" id="Taille"
								disabled="true" rendered="true" />
							<h:outputLabel value="cm" />
						</h:panelGrid>

						<p:commandButton value="Prescrire Ordonnance"
							oncomplete="OrdonnanceDialog.show()">
							<f:setPropertyActionListener target="#{ordonnanceBean.idvisite}"
								value="#{mesureAffBean.visiteid}" />
						</p:commandButton>

						<p:commandButton value="Liste Ordonnances"
							oncomplete="listeord.show()" update=":consult:basicCarousel">
							<f:setPropertyActionListener target="#{ordonnanceBean.idvisite}"
								value="#{mesureAffBean.visiteid}" />
						</p:commandButton>

						<p:commandButton value="Save"
							actionListener="#{mesureAffBean.maj()}"
							oncomplete="consultDialog.hide()" onstart="consultDialog.reset()" />

					</p:dialog>
					<!--  Ordonnance-->
					<p:dialog widgetVar="OrdonnanceDialog" header="Ordonnance Details"
						showEffect="clip" hideEffect="clip" id="ord" resizable="false"
						closable="true" closeOnEscape="true">
						<h:panelGrid id="OrdonnanceDetails" columns="3">
							<h:outputLabel value="" />
							<h:inputHidden value="#{ordonnanceBean.idvisite}" id="idv" />
							<h:outputLabel value="" />

							<h:outputLabel value="Date :" />
							<p:calendar value="#{ordonnanceBean.ordonnance.dateo}" id="date"
								rendered="true" />
							<h:outputLabel value="" />

							<h:outputLabel value="Traitement :" />
							<p:inputTextarea value="#{ordonnanceBean.ordonnance.traitement}"
								id="traitement" rendered="true" />
							<h:outputLabel value="" />

							<h:outputLabel value="Observation :" />
							<p:inputTextarea value="#{ordonnanceBean.ordonnance.observation}"
								id="observation" rendered="true" />
							<h:outputLabel value="" />
						</h:panelGrid>
						<p:commandButton value="Save"
							actionListener="#{ordonnanceBean.save()}"
							oncomplete="OrdonnanceDialog.hide()" />
					</p:dialog>
					<!--  Liste Ordonnance-->
					<p:dialog widgetVar="listeord" header="Liste Ordonnance"
						showEffect="clip" hideEffect="clip" id="lord" resizable="false"
						closable="true" closeOnEscape="true">
						<h:outputLabel value="" />
						<h:inputHidden value="#{ordonnanceBean.idvisite}" id="idhhhv"
							rendered="true" />
						<h:outputLabel value="" />
						<p:carousel id="basicCarousel"
							value="#{ordonnanceBean.ordonnances}" var="ord"
							style="width:350px;height:250px">
							<f:facet name="header">  
           Ordonnances 
    </f:facet>
							<h:panelGrid id="listOrdonnanceDetails" columns="3"
								style="height:200px">
								<!-- 								<h:outputLabel value="" /> -->
								<!-- 								<p:outputLabel value="#{ord.visite.patient.nom} #{ord.visite.patient.prenom}" id="idp" /> -->
								<!-- 								<h:outputLabel value="" /> -->


								<h:outputLabel value="Traitement :" />
								<p:outputLabel value="#{ord.traitement}" id="idtrait" />
								<h:outputLabel value="" />

								<h:outputLabel value="Observation :" />
								<p:outputLabel value="#{ord.observation}" id="idobs" />
								<h:outputLabel value="" />

								<h:outputLabel value="Date :" />
								<p:outputLabel value="#{ord.dateo}" id="idda" />
								<h:outputLabel value="" />

								<p:lightBox>
									<h:outputLink value="#">
										<h:outputText value="Imprimer " />
									</h:outputLink>

									<f:facet name="inline">
										<p:media
											value="/resources/cycles.pdf"
											width="1100px" height="600px"  />
									</f:facet>
								</p:lightBox>
							</h:panelGrid>
						</p:carousel>
					</p:dialog>
				</h:form>
			</c:when>

			<c:otherwise>
				<script language="javascript"><!--
location.replace("Login.jsf")
//-->
</script>

			</c:otherwise>
		</c:choose>
	</ui:define>

</ui:composition>
</html>